{% extends "templates/atnet_base.html" %}

{% block csslink %}
		{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>
		
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		var wasAction = false;
		
		$('#contacts').dataTable({
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": false,
			"bAutoWidth": false,
			"oLanguage": {
	            "sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
	        },
			"bProcessing": true,
			"sAjaxSource": "{{ uri_for('vie_contacts', imm_id=immeuble.key().id(), command='list_json') }}",
			"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
				$('td:eq(6)', nRow).html('<a href="javascript:void(0);" id="' + aData[6] + '" class="' + aData[0] + '">{{ _("Edit") }}</a>');
			},
		});
		
		$('#add-person').live('click', function(){
			$(this).LaunchPopup(
				{
					TableId: '#contacts',
					DivId: '#dialog-form',
					FormId: '#generated-form',
					UrlForm: "{{ uri_for('vie_contacts', imm_id=immeuble.key().id(), command='add_person') }}",
					Mode: 'add',
					Title: '{{ _("Add person") }}'
				}
			)
		});
		
		$('#add-company').live('click', function(){
			$(this).LaunchPopup(
				{
					TableId: '#contacts',
					DivId: '#dialog-form',
					FormId: '#generated-form',
					UrlForm: "{{ uri_for('vie_contacts', imm_id=immeuble.key().id(), command='add_company') }}",
					Mode: 'add',
					Title: '{{ _("Add company") }}'
				}
			)
		});
		
		$('#contacts tbody tr a').live('click', function(e) {
			var title;
			
			if ($(this).attr('class') == 'person')
				title = '{{ _("Edit person") }}';
			else
				title = '{{ _("Edit company") }}';
				
			$(this).LaunchPopup(
					{
						TableId: '#contacts',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('vie_contacts', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
						Mode: 'edit',
						Title: title
					}
				)
		});
	});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{% if not show_login %}
{{ super() }}
{% endif %}
{% endblock %}

{% block page_name %}
{{ content_header }}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_vie_de_la_copropriete.html' %}
{% endblock %}

{% block main_content %}
<p>
	<p>
		<a href="javascript:void(0);" id="add-person">{{ _('Add person') }}</a>  ||  <a href="javascript:void(0);" id="add-company">{{ _('Add company') }}</a>
	</p>
	<div id="demo">
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="contacts" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.type) }}</th>
				<th>{{ _(fields.pname) }}</th>
				<th>{{ _(fields.address) }}</th>
				<th>{{ _(fields.wwwsite) }}</th>
				<th>{{ _(fields.default_phone) }}</th>
				<th>{{ _(fields.default_email) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td colspan="6" class="dataTables_empty">{{ _('Loading data from server') }}</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.type) }}</th>
				<th>{{ _(fields.pname) }}</th>
				<th>{{ _(fields.address) }}</th>
				<th>{{ _(fields.wwwsite) }}</th>
				<th>{{ _(fields.default_phone) }}</th>
				<th>{{ _(fields.default_email) }}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>
{% endblock %}
